/**
 * 
 */
package cn.jy.map.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jy.map.domain.PulpFrequency;
import cn.jy.map.domain.RecruitmentMethod;
import cn.jy.map.mapper.RecruitmentMethodMapper;
import cn.jy.map.service.RecruitmentMethodService;
import cn.jy.map.utils.MapUtils;
import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;

/**
 * @author 刘中斐
 *@date 2018年7月2日 下午1:11:36 
 */
@Service("recruitmentMethodService")
public class RecruitmentMethodServiceImpl implements RecruitmentMethodService {
	@Autowired
	private RecruitmentMethodMapper recruitmentMethodMapper;
	@Override
	public List<RecruitmentMethod> getNewPulpsDZ(String startTime,String endTime,Integer workGroup,String jsr){
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<String> providerNo=recruitmentMethodMapper.getByNewPulps(startTime, endTime);
		StringBuilder sb=new StringBuilder();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<RecruitmentMethod> list=null;
		for (String string : providerNo) {
			sb.append("'"+string+"'"+",");
		}		
		if (workGroup!=null) {
			if (workGroup==3) {
				list=recruitmentMethodMapper.getYLDXPulps(sb.toString().substring(0, sb.length()-1));
			}else if (workGroup==0) {
				list=recruitmentMethodMapper.getAllNewPulpsDZ(sb.toString().substring(0, sb.length()-1));
			}else {
				list=recruitmentMethodMapper.getNewPulpsDZ(sb.toString().substring(0, sb.length()-1),workGroup);
			}
		}
		if (jsr!=null) {
			//			list=recruitmentMethodMapper.getByJSRName(sb.toString().substring(0, sb.length()-1), jsr);
			//list=recruitmentMethodMapper.getByJSRName(providerNo, jsr);
		}

		return list;
	}

	@Override
	public Map<String, Object> getPulpFrequency() {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("LastPulpFrequency", recruitmentMethodMapper.getLastPulpFrequency());
		map.put("ThisPulpFrequency", recruitmentMethodMapper.getThisPulpFrequency());
		return map;
	}
	@Override
	public Map<String, Object> getNewPulpsAddress(String startTime,String endTime){
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<String> providerNo=recruitmentMethodMapper.getByNewPulps(startTime, endTime);
		StringBuilder sb=new StringBuilder();
		Map<String, Object> map=new HashMap<String, Object>();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<RecruitmentMethod> list=null;
		List<RecruitmentMethod> JsrIsNull=null;
		List<RecruitmentMethod> jsrInformation=null;
		for (String string : providerNo) {
			sb.append("'"+string+"'"+",");
		}
		StringBuilder sb1=new StringBuilder();
		if (sb.length()>0) {
		
			if (startTime.substring(0,4).equals("2016")) {
				list=recruitmentMethodMapper.getAllNewPulpsDZ(sb.toString().substring(0, sb.length()-1));
				map.put("result4",list);
			}
				for (int i = 1; i < 6; i++) {
					if (i==3) {
						list=recruitmentMethodMapper.getYLDXPulps(sb.toString().substring(0, sb.length()-1));
						for (RecruitmentMethod recruitmentMethod : list) {
							sb1.append("'"+recruitmentMethod.getJSR()+"'"+",");
						}
						if (sb1.length()>0&&sb1!=null) {
							jsrInformation=recruitmentMethodMapper.getJSRInformation(sb1.toString().substring(0, sb1.length()-1));
						}
						
					}else if (i==4) {
						list=null;
						list=recruitmentMethodMapper.getNewPulpsDZ(sb.toString().substring(0, sb.length()-1),i);
						JsrIsNull=recruitmentMethodMapper.getJSRIsNull(sb.toString().substring(0, sb.length()-1));
						map.put("result6", JsrIsNull);
					}else {
						list=recruitmentMethodMapper.getNewPulpsDZ(sb.toString().substring(0, sb.length()-1),i);
					}
					map.put("result"+i, list);
					if (jsrInformation!=null&&jsrInformation.size()>0) {
						map.put("jsrInformation", jsrInformation);
					}
				}
			
			
		}
		return map;
	}
	@Override
	public Map<String,Object> getNewPulpsJsr(String startTime,String endTime){
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<String> providerNo=recruitmentMethodMapper.getByNewPulps(startTime, endTime);
		StringBuilder sb=new StringBuilder();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<RecruitmentMethod> list=null;
		for (String string : providerNo) {
			sb.append("'"+string+"'"+",");
		}
		Map<String, Object> map=new HashMap<String, Object>();
		if (sb.length()>0) {

			for (int i = 1; i <37; i++) {
				if (i<10) {
					list=recruitmentMethodMapper.getByJSRName(sb.toString().substring(0, sb.length()-1),"jsr0"+i);
					//					list=recruitmentMethodMapper.getByJSRName(providerNo,"jsr0"+i);
					map.put("jsr"+i, list);
				}else {
					list=recruitmentMethodMapper.getByJSRName(sb.toString().substring(0, sb.length()-1),"jsr"+i);
					//					list=recruitmentMethodMapper.getByJSRName(providerNo,"jsr"+i);
					map.put("jsr"+i, list);
				}

			}
		}

		return map;
	}
}
